const app = getApp();
Page({
  data: {
    timelineData: [],
  },
  onShow: function () {
    wx.request({
      url: app.globalData.url+'/fallimage',
      method:"GET",
      success: res => {
        const result=res.data
        const timelineData = this.groupByDate(result);
        console.log(timelineData)
        this.setData({
          timelineData: timelineData,
          result:result
        });
      }
    })
    
  },
  // 自定义方法，用于按日期对图片进行分组
  groupByDate: function (data) {
    const groupedData = {};
    data.forEach(item => {
      if (!groupedData[item.time]) {
        groupedData[item.time] = { time: item.time, images: [] };
      }
      groupedData[item.time].images.push(item.images);
    });
    return Object.values(groupedData);
  },
  
  
  // 预览图片
  previewImage: function (event) {
    console.log(event.currentTarget.dataset)
    var data=this.data.result
    const urls = data.map(item => {
      const regex = /https?:\/\/[^\s]+/g; // 匹配以 http:// 或 https:// 开头的 URL
      const matches = item.images.match(regex);
      return matches ? matches[0] : null;
    }).filter(url => url !== null);
    console.log(urls)
    const index = event.currentTarget.dataset.src;
    wx.previewImage({
      current: index,
      urls: urls
    });
  }
})
